#!/usr/bin/env bash
cd /var/local
#rm -rf web
#git clone http://124.223.11.108:13000/demo2099/web.git
rm -rf  nginx
mkdir nginx
mkdir -p /var/local/nginx/{conf,html,logs}
touch /var/local/nginx/html/index.html
echo   "<html><body><h1> xxxxxxxxxxxxxe</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Wed Sep 09 15:07:28 CST 2020</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>No message available</div></body></html>" >> /var/local/nginx/html/index.html
touch /var/local/nginx/conf/nginx.conf
cat >/var/local/nginx/conf/nginx.conf  <<EOF
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}
stream {
    server {
        listen              443 ssl;                    # 设置监听端口为443

        ssl_protocols       TLSv1.2 TLSv1.3;      # 设置使用的SSL协议版本

        ssl_certificate /etc/v2ray-agent/tls/$1.crt;
        ssl_certificate_key /etc/v2ray-agent/tls/$1.key;
        ssl_session_cache   shared:SSL:10m;             # SSL TCP会话缓存设置共享内存区域名为
                                                        # SSL，区域大小为10MB
        ssl_session_timeout 10m;                        # SSL TCP会话缓存超时时间为10分钟
        proxy_protocol    on; # 开启proxy_protocol获取真实ip
        proxy_pass        127.0.0.1:23342; # 后端Trojan监听端口
    }
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  ' -  [] "" '
                      '  "" '
                      '"" ""';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;


  #  server {
  #      listen       80;
  #      server_name  $1;
  #      return 301 https://\$host\$request_uri;
  #
   # }

    
}
EOF

touch /var/local/nginx/conf/nginx.conf
cat >/var/local/nginx/conf/default.conf  <<EOF
server {
    listen       1180;
    listen  [::]:1180;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

EOF
x=$[RANDOM%10+1]
echo "随机网站love${x}"
docker rm -f mynginx
docker run  -d --restart=always --name mynginx  --network host -v /etc/v2ray-agent/tls/:/etc/v2ray-agent/tls/ -v /var/local/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf -v /var/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /var/local/nginx/logs:/var/log/nginx  -v /var/local/web/love1:/usr/share/nginx/html nginx